#include "configwindow.h"
#include "ui_configwindow.h"
#include <QMessageBox>
#include <QFileInfo>

configWindow::configWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::configWindow)
{
    ui->setupUi(this);
}

configWindow::~configWindow()
{
    delete ui;
}
void configWindow::readSetting()
{
    QString str;
    QFileInfo info("./init.ini");
    if(info.isFile()==false)
    {
       QMessageBox::warning(this, "提示", "配置文件不存在");
       return ;
    }

    QSettings *config = new QSettings("init.ini",QSettings::IniFormat);
    config->setIniCodec("UTF-8");

     str = config->value("netConfig/ip").toString();
    ui->lineEdit_ip->setText(str);

     str = config->value("netConfig/port").toString();
    ui->lineEdit_port->setText(str);

}

void configWindow::writeSetting()
{
    QSettings *config = new QSettings("./init.ini",QSettings::IniFormat);
    config->setIniCodec("UTF-8");

    config->setValue("netConfig/ip",ui->lineEdit_ip->text());
    config->setValue("netConfig/port",ui->lineEdit_port->text());

    delete config;
}


void configWindow::on_writeBtn_clicked()
{
    writeSetting();
}

void configWindow::on_readBtn_clicked()
{
    readSetting();
}
